﻿-- ================================================
-- Remarks: 
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'Dasideen_ContentBinaryDataContent_Insert') 
    BEGIN
        DROP  PROCEDURE  Dasideen_ContentBinaryDataContent_Insert
    END
GO

CREATE PROC [Dasideen_ContentBinaryDataContent_Insert]
-- =============================================
-- Author:		<Ram pravesh k.r>
-- Create date: <14/05/2015>
-- Description:	<Dasideen_ContentBinaryDataContent_Insert>
-- =============================================
-- Add the parameters for the stored procedure here
	(
	            @ContentMetaDataKey int,
				@ContentBinaryData varbinary(MAX) = NULL,
				@ContentBinaryDataFileName varchar(1000) = NULL,
				@ContentBinaryDataType nvarchar(200) = NULL,
				@ContentThumbnailImage varbinary(MAX) = NULL,
				@ContentTotalDownloads nchar(10) = NULL,

				@Sys_CreatedByID varchar(50),
				@Sys_ModifiedByID varchar(50),
				@Sys_DeleteType int = 0,
				@Sys_OrganizationID int,
				@Sys_InitialPrimaryKeys varchar(max)= NULL,
				@Sys_WorkstationName varchar(50)= NULL,
				
				@Sys_DateOfCreation datetime OUTPUT
				
	)

AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
    SET NOCOUNT OFF 
	
	IF @Sys_WorkstationName = 'Default'	
	BEGIN
		SET @Sys_WorkstationName = (SELECT @@SERVERNAME);
	END
	DECLARE @CurrentDataTime datetime;
	SET @CurrentDataTime = GETDATE();

	
	BEGIN
	DELETE FROM [ContentBinaryDataContent]
	WHERE 
		(
			[ContentMetaDataKey] = @ContentMetaDataKey
		)
	END
    INSERT INTO [ContentBinaryDataContent]
            ( 
			    [ContentMetaDataKey],
			    [ContentBinaryData],
				[ContentBinaryDataFileName],
				[ContentBinaryDataType],
				[ContentThumbnailImage],
				[ContentTotalDownloads],
				
				[Sys_DateOfCreation],
				[Sys_DateOfModification],
				[Sys_CreatedByID],
				[Sys_ModifiedByID],
				[Sys_DeleteType],
				[Sys_IsDeleted],
				[Sys_OrganizationID],
				[Sys_InitialPrimaryKeys],
				[Sys_WorkstationName]
            )
	VALUES
			( 
			    @ContentMetaDataKey, 
			    @ContentBinaryData,
				@ContentBinaryDataFileName,
				@ContentBinaryDataType,
				@ContentThumbnailImage,
				@ContentTotalDownloads,
				
				@CurrentDataTime,
                @CurrentDataTime,
                @Sys_CreatedByID,
                @Sys_ModifiedByID,
                @Sys_DeleteType,
                0,
                @Sys_OrganizationID ,
                @Sys_InitialPrimaryKeys ,
                @Sys_WorkstationName
			);
	SET @Sys_DateOfCreation = @CurrentDataTime;
END
GO